<?php

require_once dirname(__FILE__) . '/../lib/connectionGeneratorConfiguration.class.php';
require_once dirname(__FILE__) . '/../lib/connectionGeneratorHelper.class.php';

/**
 * connection actions.
 *
 * @package    docplus.co.za
 * @subpackage connection
 * @author     Fox Matuku
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class connectionActions extends autoConnectionActions
{

    /**
     * Executes follow action
     *
     * @param sfRequest $request A request object
     */
    public function executeFollow(sfWebRequest $request)
    {
        $followerId = $request->getParameter('follower_id', null);
        if (!$this->getUser()->isAuthenticated())
            die("signin");

        if (!empty($followerId))
        {
            $signedInUserId = $this->getUser()->getDpUser()->getId();
            $connection = ConnectionTable::getInstance()->findOneByMembers($signedInUserId, $followerId);

            if (!is_object($connection))
            {
                // make a connection request
                $connection = new Connection();
                $connection->setFollowerId($followerId);
                $connection->setInitiatorId($signedInUserId);
                $connection->save();
            }
            die('following');
        }
    }

    /**
     * Executes unfollow action
     *
     * @param sfRequest $request A request object
     */
    public function executeUnfollow(sfWebRequest $request)
    {
        $otherUserId = $request->getParameter('user_id', null);
        if (!$this->getUser()->isAuthenticated())
            die("signin");

        if (!empty($otherUserId))
        {
            $signedInUserId = $this->getUser()->getDpUser()->getId();
            $connection = ConnectionTable::getInstance()->findOneByMembers($signedInUserId, $otherUserId);

            // check to see if the connection exists
            if (is_object($connection))
            {
                $connection->delete();
            }
            die('follow');
        }
    }

    /**
     * Executes suggest action
     *
     * @param sfRequest $request A request object
     */
    public function executeSuggest(sfWebRequest $request)
    {
        if (!empty($follow))
        {
            // make a connection request
            // send a connection request email
        }
    }

    public function executeNetwork(sfWebRequest $request)
    {
        $this->getUser()->setCurrentRoute("connection_network");        
        $this->user = GfUserTable::getInstance()->findOneBySlug($request['slug']);
    }

}
